//
//  HNSH_JoinGroupViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

#import "HNSH_JoinGroupViewController.h"

@interface HNSH_JoinGroupViewController ()

/** */
@property (nonatomic, strong)UIImageView * imgView;
/** */
@property (nonatomic, strong)UILabel * titleLabel;
/** */
@property (nonatomic, strong)UIButton * doneBtn;

@end

@implementation HNSH_JoinGroupViewController

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
   
    [self addAllViews];
    [self addAllLayout];
    
}

//MARK: Myself Methods
- (void)addAllViews{
    [self.view addSubview:self.imgView];
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.doneBtn];
}

- (void)addAllLayout{
    [self.imgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(45);
        make.top.mas_equalTo(kNavBarAndStatusBarHeight + 90);
        make.centerX.mas_equalTo(0);
    }];
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.imgView.mas_bottom).offset(16);
        make.height.mas_equalTo(22);
    }];
    [self.doneBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(28);
        make.right.mas_equalTo(-28);
        make.height.mas_equalTo(48);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(143);
    }];
}

- (void)doneBtnAction{
    [HNSH_ChatNetServer requestRongCloudGroupJoinWithQrcode:self.qrcode success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [self.view makeToast:@"加入成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: Setter Methods
- (void)setGroupModel:(HNSH_GroupInfoUserModel *)groupModel{
    _groupModel = groupModel;
    
    self.titleLabel.text = [NSString stringWithFormat:@"%@(%ld)", groupModel.name, groupModel.member_count];
}

//MARK: Getter Methods
- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
        _imgView.image = [UIImage imageNamed:@"chat_icon_myqun"];
    }
    return _imgView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _titleLabel.textColor = [UIColor appBlack333LabelColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UIButton *)doneBtn{
    if (!_doneBtn) {
        _doneBtn = [UIButton new];
        [_doneBtn setTitle:@"完成" forState:UIControlStateNormal];
        [_doneBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _doneBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        _doneBtn.layer.cornerRadius = 4;
        _doneBtn.layer.masksToBounds = YES;
        _doneBtn.backgroundColor = [UIColor appBlackLabelColor];
        [_doneBtn addTarget:self action:@selector(doneBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _doneBtn;
}

@end
